<cfcomponent output="false">
	<cfscript>
		/**
		 * Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and 
		 * new top-level domains).
		 * 
		 * 
		 * @param str	The string to check. (Required)
		 * @return 		Returns a boolean. 
		 * @author 		Juan Llanes <juanllanes@gmail.com> 
		 * @version 	1 
		 */
		function isEmail(str)
		{
			var.reg = "^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name|jobs|travel))$""
			return (
						REFindNoCase( var.reg,arguments.str )
						AND 
						len( listGetAt( arguments.str, 1, "@" ) ) LTE 64 
						AND
						len( listGetAt( arguments.str, 2, "@" ) ) LTE 255 
					) IS 1;
		}
		
	</cfscript>

	<cffunction name="send" access="public" output="false" returntype="void">

		<cfargument name="to" type="string" required="yes">
		<cfargument name="from" type="string" required="yes">
		<cfargument name="subject" type="string" required="yes">
		<cfargument name="description" type="string" required="yes">
		<cfargument name="type" type="string" required="yes">
		
		<cfif checkEmails(arguments.to) and checkEmails(arguments.from)>
			
			<cfif application.configuration.config.options.smtp.active.xmltext>
				<cfmail
					to="#arguments.to#"
					from="#arguments.from#"
					subject="#arguments.subject#"
					type="#arguments.type#"
					server="#application.configuration.config.options.smtp.server.xmltext#"
					port="#application.configuration.config.options.smtp.port.xmltext#"
					username="#application.configuration.config.options.smtp.user.xmltext#"
					password="#application.configuration.config.options.smtp.password.xmltext#">
					
					#arguments.description#
				
				</cfmail>		
			<cfelse>
				<cfmail
					to="#arguments.to#"
					from="#arguments.from#"
					subject="#arguments.subject#"
					type="#arguments.type#">
				#arguments.description#
				</cfmail>		
			</cfif>
			
			
			
			
		</cfif>
		
	</cffunction>

	<cffunction name="checkEmails" access="private" output="false">
		<cfargument name="toValue" required="true" type="string">
		<cfloop list="arguments.toValue" delimiters="," item="itemTo">
			<cfif not isEmail(itemTo)>
				<cfreturn false>
			</cfif>
		</cfloop>
		<cfreturn true>
	</cffunction>

</cfcomponent>